#!/bin/bash

SOURCEDIR=$(pwd)
choice="0"

# 下面是复制粘贴工具链的逻辑，有工具链可以不用管
#cd ~
#rm -rf ~/tools/
#mkdir -p tools/toolchain
#cd tools/toolchain
#cp ${SOURCEDIR}/../Tools/ToolChain/gcc-sigmastar-9.1.0-2019.11-x86_64_arm-eabi.tar.xz ./
#cp ${SOURCEDIR}/../Tools/ToolChain/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 ./


# 下面是复制粘贴工具链的逻辑，有工具链可以不用管
echo "in $(pwd)"

echo "关于ssz029c，你要选择在nand flash还是在nor flash编译？："
echo "1. nor"
echo "2. nand"

# 读取用户输入，是复制粘贴工具链的逻辑，有工具链可以不用管
read -p "请输入你的选择（1-2）: " choice

# 条件判断，是复制粘贴工具链的逻辑，有工具链可以不用管
if [ "$choice" = "1" ]; then
    echo "你选择了nor flash"
    #cp ${SOURCEDIR}/../Tools/ToolChain/arm-sigmastar-linux-uclibcgnueabihf-9.1.0.tar.xz ./ 
elif [ "$choice" = "2" ]; then
    echo "你选择了nand flash"
    #cp ${SOURCEDIR}/../Tools/ToolChain/gcc-11.1.0-20210608-sigmastar-glibc-x86_64_arm-linux-gnueabihf.tar.xz ./
else
    echo "无效的选择"
fi

# 下面是复制粘贴工具链的逻辑，有工具链可以不用管
#for file in *.tar.*; do
#  chmod 777 "$file"
#  tar -xvf "$file" --no-same-owner --no-same-permissions
#done


## 原有的bashrc要清空，PATH要复位的
echo "===================================================================="
echo $(pwd)
if [ "$choice" = "1" ]; then
    export PATH=${PATH}:$(pwd)/gcc-sigmastar-9.1.0-2019.11-x86_64_arm-eabi/bin:$(pwd)/gcc-arm-none-eabi-10.3-2021.10/bin:$(pwd)/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/bin
elif [ "$choice" = "2" ]; then
    export PATH=${PATH}:$(pwd)/gcc-sigmastar-9.1.0-2019.11-x86_64_arm-eabi/bin:$(pwd)/gcc-arm-none-eabi-10.3-2021.10/bin:$(pwd)/gcc-11.1.0-20210608-sigmastar-glibc-x86_64_arm-linux-gnueabihf/bin
else
    echo "无效的选择"
fi

echo "===================================================================="
echo $PATH

shopt -s expand_aliases
alias python=python2

python --version

#在这一步之前，我把所有文件中的#!/bin/sh在vscode中手动替换成#!/bin/bash
#同时需要把某些脚本里面的python改成python2,但是得需要先编译，然后看报错信息后再具体调整
#之后某些脚本里面有漏网之鱼，要手动改成bash
cd ${SOURCEDIR}/project


make SHELL=/bin/bash ipc-rtos_iford.nor.uclibc-9.1.0-ramdisk.ssz029c.128.qfn128_ddr3_demo_aov_defconfig

# make SHELL=/bin/bash clean

make SHELL=/bin/bash image -j16
